<?php
class Database_Connector_Connective extends PDO{
    public function __construct($dsn,$user,$pwd,$options){
        try{
            // echo $dsn;
            parent::__construct($dsn,$user,$pwd,$options);
            $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
            $this->setAttribute(PDO::ATTR_ORACLE_NULLS,PDO::NULL_TO_STRING);
            
        }catch (PDOException $e) {
            $this->error = $e->getMessage();
            echo $this->error;
            // die($this->error);
            //return false;
        }
    }
    public static function getInstance(){
        $_class = get_called_class();
        if(Yaf_Registry::has($_class)){
            return Yaf_Registry::get($_class);
            
        } else {
            $db = new $_class();
            Yaf_Registry::set($_class,$db);
            return $db;
        }
    }
    public function getConfig(){
        if(Yaf_Registry::has('db_config')){ 
            $driver = Yaf_Registry::get('db_config')->db->driver;
            $db_config = Yaf_Registry::get('db_config')->{$driver};
        } else {
            $config = new Yaf_Config_Ini(CONFIG_PATH.'database.ini');
            $driver = $config->driver;
            $db_config = $config->{$driver};
        }
        return $db_config;
    }
    public function __destruct(){
    }
}
